package com.health.mapp.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import com.health.db.model.GoodsListCouse;
import com.health.db.model.GoodsListExample;
import com.health.db.model.GoodsListTemp;
import com.health.db.service.sm.IGoodsListService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.QueryEntityGoodsListReq;
import com.health.mapp.bean.QueryEntityGoodsListResp;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;
/**
 * 查看商品种类 查询商品信息
 * 
 * @author Yuchong
 *
 */
public class QueryEntityGoodsListImpl implements ActionInterface {

	private IGoodsListService goodsListService  ;
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
	 
		
		QueryEntityGoodsListReq req = (QueryEntityGoodsListReq) reqBean;
		QueryEntityGoodsListResp _resp = new QueryEntityGoodsListResp();
		
		if (StringUtils.isNotBlank(req.getGoodsId())) {
			
			GoodsListExample example = new GoodsListExample();
			example.setGoodsid(Long.valueOf(req.getGoodsId()));
			List<GoodsListTemp> list =  goodsListService.selectBySimple(example);
			if (list.size()==1) {
				_resp.setGoodsList(list);
			}else{
				
				_resp.setErrorCode(ResultCode.OPERATION_ORDER_ERROR_3018);
				_resp.setErrorMsg(ResultCode.OPERATION_ORDER_ERROR_3018_NOTE);
			}
			
		}else
		if (StringUtils.isNotBlank(req.getGoodsType())) {
			
			GoodsListExample example = new GoodsListExample();
			Integer pageNo=req.getPageNo();
			Integer pageSize=req.getPageNum();
			
			if(null!=pageNo&&null!=pageSize){
				example.setOffset((pageNo.intValue()-1)*pageSize.intValue());
				example.setPageSize(pageSize.intValue());
				_resp.setPageNo(pageNo);
				_resp.setPageNum(pageSize);
			}
			example.setTypeid(Integer.valueOf(req.getGoodsType()));
			
			if (req.getGoodsType().equals("61")) {
				
				List<GoodsListCouse> list= goodsListService.selectBySimpleCouse(example);
				_resp.setCourseList(list);
				
			}else{
				List<GoodsListTemp> list =goodsListService.selectBySimple(example);
				_resp.setGoodsList(list);
			}
			
		
		
	 
		}else{
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
			return _resp;
		}
		
		return _resp;
	}
	public IGoodsListService getGoodsListService() {
		return goodsListService;
	}
	public void setGoodsListService(IGoodsListService goodsListService) {
		this.goodsListService = goodsListService;
	}
	
}
